extends Control

@onready var static_input: Node = $"../static_machine/static_input"
@onready var date_label: Label = $MarginContainer/VBoxContainer/date_label
@export var self_despline = SelfDisciplineData.new()
var SDL = ResourceLoader.load("res://self_descipline_list.tres")
var date : Dictionary

func _on_static_input_start_input() -> void:
	show_time()

# 调用状态机的退出
func _on_exit_button_pressed() -> void:
	static_input._exit()


func _on_save_button_pressed() -> void:
	# 获取最新保存的自律文件
	var latest_SDL_index = len(SDL.self_displine_list)
	print_debug(latest_SDL_index)
	if latest_SDL_index == 0 or SDL.self_displine_list[latest_SDL_index].timestamp != self_despline.timestamp:
		print_debug("新文件诶")
		SDL.self_displine_list.append(self_despline)
	else:
		print_debug("需要新建文件了")
		SDL.self_displine_list[latest_SDL_index] = self_despline
	ResourceSaver.save(SDL,"res://self_descipline_list.tres")

# 配置input界面显示日期
func show_time()->void:
	date = self_despline.get_time()
	print_debug(self_despline.timestamp)
	date_label.text = "{0}年{1}月{2}日".format([date.year,date.month,date.day])
